package com.atguigu.userprofile.dao;

import com.atguigu.userprofile.bean.TagInfo;
import com.atguigu.userprofile.util.MySqlUtil;

import java.util.List;

/**
 * 负责TagInfo的增删改查
 */
public class TagInfoDao {


    public static void main(String[] args) {
        List<TagInfo> tagInfos = selectTagInfosWithTaskEnable();
        tagInfos.forEach(System.out::println);
    }

    public static List<TagInfo> selectTagInfosWithTaskEnable(){
        String sql = "SELECT \n" +
                " ti.id , ti.tag_code , ti.tag_name , ti.tag_level , ti.parent_tag_id , ti.tag_type , ti.tag_value_type , ti.tag_value_limit , ti.tag_value_step , ti.tag_task_id , ti.tag_comment , ti.update_time , ti.create_time \n" +
                "FROM \n" +
                " tag_info ti JOIN  task_info tk ON ti.tag_task_id = tk.id\n" +
                "WHERE tk.task_status = 1" ;
        List<TagInfo> tagInfos = MySqlUtil.selectList(sql, TagInfo.class, true);
        return tagInfos ;
    }



    public static TagInfo selectTagInfoByTaskId(String taskId){
        String sql = "SELECT \n" +
                " id , tag_code , tag_name , tag_level , parent_tag_id , tag_type , tag_value_type , tag_value_limit , tag_value_step , tag_task_id , tag_comment , update_time , create_time \n" +
                "FROM \n" +
                " tag_info \n" +
                " WHERE tag_task_id = " + taskId ;
        TagInfo tagInfo = MySqlUtil.selectOne(sql, TagInfo.class, true);
        return tagInfo ;
    }
}
